package caip2024p.rcv6;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {
    static final int N = 100010;

    public static void main(String[] args) throws IOException {
    	//输入优化
        BufferedReader read = new BufferedReader(new InputStreamReader(System.in));

        // 输入 n 和 d
        String[] lineArr = read.readLine().split(" ");
        int n = Integer.parseInt(lineArr[0]);
        int d = Integer.parseInt(lineArr[1]);

        // 初始化数组 a 和 b
        int[] a = new int[N];
        int[] b = new int[N];

        
        // 输入数组 a
        lineArr = read.readLine().split(" ");
        for (int i = 1; i <= n; i++) {
            a[i] = Integer.parseInt(lineArr[i-1]);
        }

        // 处理 d 天的数据
        for (int i = 1; i <= n; i++) {
        	lineArr = read.readLine().split(" ");
            for (int j = 1; j <= d*2; j+=2) {
                int x = Integer.parseInt(lineArr[j-1]);
                int y = Integer.parseInt(lineArr[j]);
                b[i] += x; // 累加 b[i]
                a[i] -= (x - y); // 更新 a[i]
            }
        }

        // 找到 b 数组中的最大值 mx
        int mx = 0;
        for (int i = 1; i <= n; i++) {
            mx = Math.max(mx, b[i]);
        }

        // 输出结果
        StringBuilder sb = new StringBuilder();
        for (int i = 1; i <= n; i++) {
            //System.out.print(a[i]);
            sb.append(a[i]);
            if (b[i] == mx) {
                //System.out.println("*");
            	sb.append("*\n");
            } else {
                //System.out.println();
            	sb.append("\n");
            }
        }

        System.out.print(sb.toString());
        // 关闭 BufferedReader
        read.close();
    }
}
